package szad.org;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import szad.org.dao.GsonRequest;
import szad.org.dao.GsonResponse;
import szad.org.dao.Szakember;
import szad.org.model.Dao;
import szad.org.player.Player;
import szad.org.view.MainFrame;

import com.google.gson.Gson;
import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;

public class Main {

	/**
	 * @param args
	 */
	private Player player;

	public static void main(String[] args) {
		
		
		//String url = "http://localhost:3732/sedcup2013/teams/A-Team";
		/*String url = "http://localhost:3723/sedcup2013/teams/Client1";
        if (args.length != 0) {
            url = args[0];
        }
        //String gstr = "{\"status\":\"FirstTurn\",\"secondsLeft\":100,\"turn\":1,\"money\":1000,\"agents\":[],\"tasks\":[{\"coordinate\":2,\"type\":\"java\",\"duration\":2,\"remaining\":2,\"profit\":2,\"penalty\":5,\"status\":\"free\"},{\"coordinate\":3,\"type\":\"c++\",\"duration\":16,\"remaining\":16,\"profit\":4,\"penalty\":10,\"status\":\"free\"},{\"coordinate\":18,\"type\":\"java\",\"duration\":16,\"remaining\":16,\"profit\":9,\"penalty\":3,\"status\":\"free\"},{\"coordinate\":4,\"type\":\"c#\",\"duration\":20,\"remaining\":20,\"profit\":3,\"penalty\":3,\"status\":\"free\"},{\"coordinate\":6,\"type\":\"c++\",\"duration\":20,\"remaining\":20,\"profit\":9,\"penalty\":3,\"status\":\"free\"},{\"coordinate\":22,\"type\":\"java\",\"duration\":16,\"remaining\":16,\"profit\":6,\"penalty\":2,\"status\":\"free\"},{\"coordinate\":24,\"type\":\"c#\",\"duration\":14,\"remaining\":14,\"profit\":5,\"penalty\":10,\"status\":\"free\"},{\"coordinate\":10,\"type\":\"c++\",\"duration\":12,\"remaining\":12,\"profit\":4,\"penalty\":3,\"status\":\"free\"},{\"coordinate\":11,\"type\":\"c#\",\"duration\":12,\"remaining\":12,\"profit\":3,\"penalty\":6,\"status\":\"free\"}],\"mapSize\":5,\"roadBlocks\":{\"4\":[5],\"6\":[1],\"7\":[2],\"8\":[9],\"9\":[4],\"12\":[7],\"14\":[9],\"17\":[18],\"18\":[19],\"21\":[22],\"23\":[24],\"22\":[23],\"24\":[25]},\"headQuarters\":[{\"coordinate\":12,\"owner\":\"me\"},{\"coordinate\":5,\"owner\":\"enemy\"}]}";
        //System.out.println(gstr);

        Player player = new Player();
        Gson gson = new Gson();
        
        

        HttpClient httpclient = new DefaultHttpClient(); // create the http client
        // httpclient.getParams().setParameter("http.socket.timeout", new Integer(3600000)); // set the timeout if needed
        System.out.println("Connecting to " + url + "...");
        try {
        	//init
            HttpPost httppost = new HttpPost(url); // create an object for the post message
            GsonRequest gsreq = new GsonRequest(0);
            String emptyRequest = gson.toJson(gsreq, GsonRequest.class); 
            
            System.out.println("request: " + emptyRequest);
            StringEntity strentity = new StringEntity(emptyRequest, "UTF-8"); // pack it into a StringEntity
            strentity.setContentType("application/json"); // set the type to json
            httppost.setEntity(strentity); // add the content the post message

            HttpResponse response = httpclient.execute(httppost); // post the message and wait for response
            HttpEntity entity = response.getEntity(); // get the entity
            final String str = EntityUtils.toString(entity, "UTF-8"); // unpack the entity
            System.out.println("response: " + str);
            
            
            System.out.println(str);
            GsonResponse gsresp = gson.fromJson(str, GsonResponse.class);
            player.initMap(gsresp);*/
   
		Dao dao = new Dao(6);
		dao.setSzekhely(3, "me");
		dao.setSzekhely(20, "enemy");
		dao.ujSzakember(5, "c++", "520", "me");
		dao.ujSzakember(25, "c++", "520", "enemy");
		





            MainFrame mFrame = new MainFrame(dao);
            mFrame.setVisible(true);
            
            mFrame.rePaint();

            
     
        System.out.println("Finished.");

	}
	

}
